<?php

namespace falcon5\inc\WPProviders;


use falcon5\inc\Base\Common;
use falcon5\inc\Base\ServiceProviderInterface;
use falcon5\inc\Helpers\AssetsHelper;

class AdminScripts implements ServiceProviderInterface
{

    public function register()
    {
        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), 10, 1 );
    }


    function enqueue($hook) {
        $restUrl = trim(falcon5_home_url(), '/');
        $assets = esc_url( AssetsHelper::getAssetUri() );
        wp_enqueue_style( Common::PLUGIN_ID . '-notices', $assets . '/css/falcon5-notices.css' );
        if ($hook == 'toplevel_page_falcon5-settings') {
            wp_enqueue_style( Common::PLUGIN_ID . '-admin', $assets . '/css/falcon5-admin.css' );
            wp_enqueue_style( Common::PLUGIN_ID . '-init', $assets . '/css/page/falcon5-init.css' );
            wp_enqueue_style( Common::PLUGIN_ID . '-setting', $assets . '/css/page/falcon5-setting.css?random='.time() );
            wp_enqueue_script( Common::PLUGIN_ID . '-monitor', $assets . '/js/falcon5-monitor.js' );
            wp_enqueue_script( Common::PLUGIN_ID . '-utils', $assets . '/js/falcon5-utils.js' );
            wp_enqueue_script( Common::PLUGIN_ID . '-admin', $assets . '/js/falcon5-admin.js', [Common::PLUGIN_ID . '-utils'] );
            wp_enqueue_script( Common::PLUGIN_ID . '-setting-page', $assets . '/js/page/falcon5-setting.js?random='.time(), [Common::PLUGIN_ID . '-admin'] );
            wp_enqueue_script( Common::PLUGIN_ID . '-pagination', $assets . '/js/page/falcon5-pagination.js', [Common::PLUGIN_ID . '-admin'] );
            wp_enqueue_script( Common::PLUGIN_ID . '-cache-page', $assets . '/js/page/falcon5-cache.js', [Common::PLUGIN_ID . '-admin', Common::PLUGIN_ID . '-pagination'] );
            wp_localize_script(Common::PLUGIN_ID . '-setting-page', Common::PLUGIN_ID . '_ajax_config', [
                'ajax_url' => falcon5_admin_url( 'admin-ajax.php' ),
                'rest_url' => rest_url(),
            ]);
            wp_localize_script(Common::PLUGIN_ID . '-cache-page', Common::PLUGIN_ID . '_ajax_config', [
                'ajax_url' => falcon5_admin_url( 'admin-ajax.php' ),
                'rest_url' => rest_url(),
            ]);
        }

    }
}